<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 4.2.0">
  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">

<link rel="stylesheet" href="/css/main.css">


<link rel="stylesheet" href="/lib/font-awesome/css/all.min.css">

<script id="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {"hostname":"yoursite.com","root":"/","scheme":"Mist","version":"7.8.0","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12,"onmobile":false},"copycode":{"enable":false,"show_result":false,"style":null},"back2top":{"enable":true,"sidebar":false,"scrollpercent":false},"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":false,"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"algolia":{"hits":{"per_page":10},"labels":{"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}},"localsearch":{"enable":false,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}}};
  </script>

  <meta name="description" content="MyBaits框架剖析">
<meta property="og:type" content="article">
<meta property="og:title" content="MyBaits">
<meta property="og:url" content="http://yoursite.com/2020/05/09/MyBaits/index.html">
<meta property="og:site_name" content="瑜晨の小窝">
<meta property="og:description" content="MyBaits框架剖析">
<meta property="og:locale" content="zh_CN">
<meta property="article:published_time" content="2020-05-09T14:58:49.805Z">
<meta property="article:modified_time" content="2020-05-09T16:07:50.915Z">
<meta property="article:author" content="Shen Yu Chen">
<meta property="article:tag" content="框架">
<meta name="twitter:card" content="summary">

<link rel="canonical" href="http://yoursite.com/2020/05/09/MyBaits/">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome : false,
    isPost : true,
    lang   : 'zh-CN'
  };
</script>

  <title>MyBaits | 瑜晨の小窝</title>
  






  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

</head>

<body itemscope itemtype="http://schema.org/WebPage">
  <div class="container use-motion">
    <div class="headband"></div>

    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏">
      <span class="toggle-line toggle-line-first"></span>
      <span class="toggle-line toggle-line-middle"></span>
      <span class="toggle-line toggle-line-last"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <h1 class="site-title">瑜晨の小窝</h1>
      <span class="logo-line-after"><i></i></span>
    </a>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
    </div>
  </div>
</div>




<nav class="site-nav">
  <ul id="menu" class="main-menu menu">
        <li class="menu-item menu-item-home">

    <a href="/" rel="section"><i class="fa fa-home fa-fw"></i>首页</a>

  </li>
        <li class="menu-item menu-item-archives">

    <a href="/archives/" rel="section"><i class="fa fa-archive fa-fw"></i>归档</a>

  </li>
  </ul>
</nav>




</div>
    </header>

    
  <div class="back-to-top">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>


    <main class="main">
      <div class="main-inner">
        <div class="content-wrap">
          

          <div class="content post posts-expand">
            

    
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/2020/05/09/MyBaits/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="Shen Yu Chen">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="瑜晨の小窝">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          MyBaits
        </h1>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-calendar"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2020-05-09 22:58:49" itemprop="dateCreated datePublished" datetime="2020-05-09T22:58:49+08:00">2020-05-09</time>
            </span>
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="far fa-calendar-check"></i>
                </span>
                <span class="post-meta-item-text">更新于</span>
                <time title="修改时间：2020-05-10 00:07:50" itemprop="dateModified" datetime="2020-05-10T00:07:50+08:00">2020-05-10</time>
              </span>

          
            <div class="post-description">MyBaits框架剖析</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
        <h1 id="MyBaits"><a href="#MyBaits" class="headerlink" title="MyBaits"></a>MyBaits</h1><h2 id="相关概念"><a href="#相关概念" class="headerlink" title="相关概念"></a>相关概念</h2><p>mybaits的本质就是对jdbc的封装</p>
<p>支持定制化SQL,存储过程及高级映射</p>
<p>半自动化轻量级orm框架</p>
<h2 id="配置文件深入"><a href="#配置文件深入" class="headerlink" title="配置文件深入"></a>配置文件深入</h2><h3 id="全局配置文件-sqlMapConfig"><a href="#全局配置文件-sqlMapConfig" class="headerlink" title="全局配置文件(sqlMapConfig)"></a>全局配置文件(sqlMapConfig)</h3><p>mybatis全局配置文件,可自定义名称,一般我们默认都是以sqlMapConfig命名,其子标签如下</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">properties</span>&gt;</span></span><br><span class="line">	加载外部properties文件</span><br><span class="line">	需放在 <span class="tag">&lt;<span class="name">configuration</span>&gt;</span>下子标签首位 ,通过$&#123;&#125;引用其内容</span><br><span class="line">    </span><br><span class="line"><span class="tag">&lt;<span class="name">typeAliases</span>&gt;</span></span><br><span class="line"> 	给实体类全限限定类名起别名</span><br><span class="line">	子标签<span class="tag">&lt;<span class="name">typeAlias</span>&gt;</span>给单独类起别名</span><br><span class="line">	子标签<span class="tag">&lt;<span class="name">package</span>&gt;</span>给包下所有类起别名,别名就是类名,不区分大小写</span><br><span class="line">	<span class="tag">&lt;<span class="name">mappers</span>&gt;</span>引入映射配置文件时使用<span class="tag">&lt;<span class="name">package</span>&gt;</span>,需保证映射配置文件和接口同包同名</span><br></pre></td></tr></table></figure>

<h3 id="映射配置文件-xxxMapper-xml"><a href="#映射配置文件-xxxMapper-xml" class="headerlink" title="映射配置文件(xxxMapper.xml)"></a>映射配置文件(xxxMapper.xml)</h3><p>其可配置动态SQL标签如下</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">sql</span>&gt;</span><span class="tag">&lt;/<span class="name">sql</span>&gt;</span></span><br><span class="line">	抽取sql片段,使用<span class="tag">&lt; <span class="attr">include</span> &gt;</span>标签复用</span><br><span class="line">        </span><br><span class="line"><span class="tag">&lt;<span class="name">if</span>&gt;</span><span class="tag">&lt;/<span class="name">if</span>&gt;</span></span><br><span class="line">	条件判断</span><br><span class="line"></span><br><span class="line"><span class="tag">&lt;<span class="name">foreach</span>&gt;</span><span class="tag">&lt;/<span class="name">foreach</span>&gt;</span></span><br><span class="line">    循环,可配置属性如下:</span><br><span class="line">    collection: 要做foreach的对象，作为入参时，List默认用"list"代替作为键，</span><br><span class="line">    数组默认用"array"代替作为键，Map没有默认的键,使用封装时的key作为键</span><br><span class="line">    open: 定义开始部分</span><br><span class="line">    close: 定义结束部分</span><br><span class="line">    item: 集合中元素迭代时的别名</span><br><span class="line">    separator: 元素之间的分隔符</span><br><span class="line">    index: 在list和数组中,index是元素的序号,在map中,index是元素的key</span><br><span class="line"></span><br><span class="line"><span class="tag">&lt;<span class="name">choose</span>&gt;</span></span><br><span class="line">	<span class="tag">&lt;<span class="name">when</span>&gt;</span><span class="tag">&lt;/<span class="name">when</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">otherwise</span>&gt;</span><span class="tag">&lt;/<span class="name">otherwise</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">choose</span>&gt;</span> </span><br><span class="line">	多条件判断</span><br><span class="line"></span><br><span class="line"><span class="tag">&lt;<span class="name">where</span>&gt;</span><span class="tag">&lt;/<span class="name">where</span>&gt;</span></span><br><span class="line">	动态配置WHERE关键字,滤掉条件语句中第一个and或or关键字,可以不用写1=1了</span><br><span class="line"></span><br><span class="line"><span class="tag">&lt;<span class="name">set</span>&gt;</span><span class="tag">&lt;/<span class="name">set</span>&gt;</span></span><br><span class="line">	update时动态配置SET关键字,剔除追加到条件末尾的任何不相关的逗号</span><br><span class="line"></span><br><span class="line"><span class="tag">&lt;<span class="name">trim</span>&gt;</span><span class="tag">&lt;/<span class="name">trim</span>&gt;</span></span><br><span class="line">	格式化标记,可以通过其提供的前缀,前缀判断和后缀,后缀判断格式化sql</span><br></pre></td></tr></table></figure>


    </div>

    
    
    

      <footer class="post-footer">
          <div class="post-tags">
              <a href="/tags/%E6%A1%86%E6%9E%B6/" rel="tag"># 框架</a>
          </div>

        


        
    <div class="post-nav">
      <div class="post-nav-item"></div>
      <div class="post-nav-item">
    <a href="/2020/05/10/SpringMvc/" rel="next" title="SpringMvc">
      SpringMvc <i class="fa fa-chevron-right"></i>
    </a></div>
    </div>
      </footer>
    
  </article>
  
  
  



          </div>
          

<script>
  window.addEventListener('tabs:register', () => {
    let { activeClass } = CONFIG.comments;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      let commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>

        </div>
          
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line toggle-line-first"></span>
    <span class="toggle-line toggle-line-middle"></span>
    <span class="toggle-line toggle-line-last"></span>
  </div>

  <aside class="sidebar">
    <div class="sidebar-inner">

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
          <div class="post-toc motion-element"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#MyBaits"><span class="nav-number">1.</span> <span class="nav-text">MyBaits</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#相关概念"><span class="nav-number">1.1.</span> <span class="nav-text">相关概念</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#配置文件深入"><span class="nav-number">1.2.</span> <span class="nav-text">配置文件深入</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#全局配置文件-sqlMapConfig"><span class="nav-number">1.2.1.</span> <span class="nav-text">全局配置文件(sqlMapConfig)</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#映射配置文件-xxxMapper-xml"><span class="nav-number">1.2.2.</span> <span class="nav-text">映射配置文件(xxxMapper.xml)</span></a></li></ol></li></ol></li></ol></div>
      </div>
      <!--/noindex-->

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
  <p class="site-author-name" itemprop="name">Shen Yu Chen</p>
  <div class="site-description" itemprop="description"></div>
</div>
<div class="site-state-wrap motion-element">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/archives/">
        
          <span class="site-state-item-count">3</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-tags">
        <span class="site-state-item-count">2</span>
        <span class="site-state-item-name">标签</span>
      </div>
  </nav>
</div>



      </div>

    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer class="footer">
      <div class="footer-inner">
        

        

<div class="copyright">
  
  &copy; 
  <span itemprop="copyrightYear">2020</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">Shen Yu Chen</span>
</div>
  <div class="powered-by">由 <a href="https://hexo.io/" class="theme-link" rel="noopener" target="_blank">Hexo</a> & <a href="https://mist.theme-next.org/" class="theme-link" rel="noopener" target="_blank">NexT.Mist</a> 强力驱动
  </div>

        








      </div>
    </footer>
  </div>

  
  <script src="/lib/anime.min.js"></script>
  <script src="/lib/velocity/velocity.min.js"></script>
  <script src="/lib/velocity/velocity.ui.min.js"></script>

<script src="/js/utils.js"></script>

<script src="/js/motion.js"></script>


<script src="/js/schemes/muse.js"></script>


<script src="/js/next-boot.js"></script>




  















  

  

</body>
</html>
